#include "Stdafx.h"
#include "Texture.h"

#include "RenderDevice.h"
#include "Texture2D.h"

namespace WindGE
{
	Texture::Texture()
		: tex_srv_(nullptr)
	{
	}

	Texture::~Texture()
	{
		release();
	}

	bool Texture::init(RenderDevicePtr renderDevice, Texture2DPtr tex)
	{
		desc_.Format = tex->desc().Format;
		desc_.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
		desc_.Texture2D.MipLevels = tex->desc().MipLevels;
		desc_.Texture2D.MostDetailedMip = 0;

		HRESULT hr = renderDevice->device()->CreateShaderResourceView(tex->d3dptr(), &desc_, &tex_srv_);
		if (FAILED(hr)) return false;

		return true;
	}

	bool Texture::init(RenderDevicePtr renderDevice, Texture2D& tex)
	{
		desc_.Format = tex.desc().Format;
		desc_.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
		desc_.Texture2D.MipLevels = tex.desc().MipLevels;
		desc_.Texture2D.MostDetailedMip = 0;

		HRESULT hr = renderDevice->device()->CreateShaderResourceView(tex.d3dptr(), &desc_, &tex_srv_);
		if (FAILED(hr)) return false;

		return true;
	}

	bool Texture::init(RenderDevicePtr renderDevice, const std::vector<Texture2DPtr>& texList)
	{
		return true;
	}

	void Texture::release()
	{
		safe_release(tex_srv_);
	}

}//end namespace WindGE


